/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.esm.pdawms.util;

import com.esm.pdawms.database.manager.SystemCenter;

import java.util.HashMap;
import java.util.Map;

import zuo.biao.library.interfaces.OnHttpResponseListener;
import zuo.biao.library.manager.HttpManager;

public class HttpRequest {

    /*
     * http://192.168.0.121:8086/api/wms/hprkcodedetail?hprkcode=P4
     * 入库货品编号详情
     */
    public static void hprkcodedetail(String hprkcode, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("hprkcode", Utils.urlEncoded(hprkcode));
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/hprkcodedetail", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/kwdetail?kwbh=A1-3-2-6
     * 库位内货品列表
     */
    public static void kwdetail(String kwbh, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("kwbh", kwbh);
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/kwdetail", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/kwbindhprkcode?kwbh=A1_1_1&hprkcode=P4
     * 入库
     */
    public static void kwbindhprkcode(String kwbh, String hprkcode, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("kwbh", kwbh);
        request.put("caozuo", SystemCenter.getInstance().caozuo);
        request.put("hprkcode", Utils.urlEncoded(hprkcode));
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/kwbindhprkcode", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/kwunbindhprkcode?kwbh=A1_1_1&hprkcode=P4&llbh=ew&bcpcpbh=123
     * 出库
     */
    public static void kwunbindhprkcode(String kwbh, String hprkcode, String bcpcpbh, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("kwbh", kwbh);
        request.put("caozuo", SystemCenter.getInstance().caozuo);
        request.put("bcpcpbh", bcpcpbh);
        request.put("hprkcode", Utils.urlEncoded(hprkcode));
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/kwunbindhprkcode", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/bcpcpdandetail?name=LL_0001
     * 扫半成品成品出库单
     */
    public static void bcpcpdandetail(String name, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("name", name);
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/bcpcpdandetail", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/createhprkcodeforruku?bcpcpdan=Q2230215001&hpcode=130301A002&hegenum=1&onenum=35
     * 检验入库单货品
     */
    public static void createhprkcodeforruku(String dxname, String bcpcpdan, String hpcode, String caozuo, float hegenum, int num1, float onenum1, int num2, float onenum2, String ph, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();

        request.put("hpcode", hpcode);
        request.put("caozuo", caozuo);
        request.put("hegenum", hegenum);
        request.put("num1", num1);
        request.put("onenum1", onenum1);
        request.put("num2", num2);
        request.put("onenum2", onenum2);
        request.put("dyxb", 0);
        if (dxname.length() > 0) {
            request.put("hpbh", dxname);
            HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/addsmallhprkcode", requestCode, listener);
        } else {
            request.put("bcpcpdan", bcpcpdan);
            request.put("ph", ph);
            HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/createhprkcodeforruku", requestCode, listener);
        }
    }

    /*
     * http://192.168.0.121:8086/api/wms/esmscan?bh=LL_0001
     * 扫任意码
     */
    public static void esmscan(String bh, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("bh", Utils.urlEncoded(bh));
        HttpManager.getInstance().get(request, "http://192.168.0.121:8086/api/wms/esmscan", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/updateonenum?hprkcode=A1_1_1&hegenum=6&caozuo=12
     * 变动小标包含的货品数
     */
    public static void updateonenum(String hprkcode, String dbh, float num_after, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("hprkcode", Utils.urlEncoded(hprkcode));
        request.put("caozuo", SystemCenter.getInstance().caozuo);
        request.put("num_after", "" + num_after);
        request.put("dbh", "" + dbh);
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/updateonenum", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/sqdanchuku?sqdname=CG_0
     * 申请单出库确认
     */
    public static void sqdanchuku(String sqdname, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("sqdname", sqdname);
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/sqdanchuku", requestCode, listener);
    }

    /*
     * http://192.168.0.121:8086/api/wms/updateonenum?hprkcode=A1_1_1&hegenum=6&caozuo=12
     * 半成品入库复检小标
     */
    public static void updatehknum(String hprkcode, float num, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("hprkcode", hprkcode);
        request.put("caozuo", SystemCenter.getInstance().caozuo);
        request.put("num", "" + num);
        HttpManager.getInstance().post(request, "http://192.168.0.121:8086/api/wms/updatehknum", requestCode, listener);
    }
}